home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / yamp16.zip / VIRT.H < prev    next >
C/C++ Source or Header  |  1993-01-11  |  20KB  |  696 lines

  1.  
  2.  
  3. /*
  4. YAMP - Yet Another Matrix Program
  5. Version: 1.6  
  6. Author: Mark Von Tress, Ph.D.
  7. Date: 01/11/93  
  8.  
  9. Copyright(c) Mark Von Tress 1993
  10. Portions of this code are (c) 1991 by Allen I. Holub and are used by
  11. permission
  12.  
  13. DISCLAIMER: THIS PROGRAM IS PROVIDED AS IS, WITHOUT ANY
  14. WARRANTY, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  15. TO FITNESS FOR A PARTICULAR PURPOSE. THE AUTHOR DISCLAIMS
  16. ALL LIABILITY FOR DIRECT OR CONSEQUENTIAL DAMAGES RESULTING
  17. FROM USE OF THIS PROGRAM.
  18.  
  19. */
  20.  
  21. #include <d:dos.h>
  22. #include <d:stdlib.h>
  23. #include <d:stdio.h>
  24. #include <d:math.h>
  25. #include <d:string.h>
  26. #include <d:io.h>
  27. #include <d:fcntl.h>
  28. #include <d:errno.h>
  29. #include <d:types.h>
  30. #include <d:stat.h>
  31. #include <d:iostream.h>
  32.  
  33.  
  34. //#define IN_RAM  // for in ram version
  35.  
  36. #define STACKLENGTH 16352
  37.  
  38. #define NDECS 10
  39. #define ZERO (1.0E-8)
  40.  
  41. #ifndef SIGNATURE
  42. #define SIGNATURE 0x5a5a
  43. #endif
  44.  
  45.  
  46. /////////////////////////////////////////// string type class
  47.  
  48. #define MAXCHARS 80
  49.  
  50.  
  51. class strtype {
  52.     private:
  53.        char name[MAXCHARS];
  54.    public:
  55.       strtype( strtype &str );
  56.       strtype( char *str );
  57.       strtype( void );
  58.       strtype operator+(strtype str);
  59.       strtype operator+(const char *str);
  60.       strtype operator=(strtype str);
  61.       strtype operator=(const char *str);
  62.       void Showname( void ) { printf("%s",name) ;}
  63.       char *StringAddress( void ) { return name; }
  64.    };
  65.  
  66.  
  67. ////////////////////////////////////////////////////////////////
  68.  
  69.  
  70.  
  71. ////////////////////////////// inram version
  72. #ifdef IN_RAM
  73.  
  74. #ifndef HUGE_POINTER
  75.  
  76. // define HUGE_PTR for MSC7 to be __huge. The value __far
  77. // works for MSC7.01 which is a patch of version 7.
  78.  
  79. #ifdef _MSC_VER
  80. #define HUGE_POINTER  __far
  81. #endif
  82. // define huge for BC3.1
  83. #ifdef __BCPLUSPLUS__
  84. #define HUGE_POINTER  far
  85. #endif
  86.  
  87. // need to define this for other compilers for huge keyword
  88. #ifndef HUGE_POINTER
  89. #define HUGE_POINTER
  90. #endif
  91.  
  92. #endif
  93.  
  94. #include <alloc.h>
  95.  
  96. // for compatability with large model.
  97. #ifndef VCLOSE
  98. #define VCLOSE 1
  99. #define vclose()
  100. #endif
  101.  
  102. typedef struct vdoub{
  103.     // use huge pointer to avoid memory leak in far pointer delete
  104.     // in MSC7. It doesn't release big chunks correctly. huge
  105.     // pointers work ok. 06/07/92
  106.     int nrefs;
  107.     double HUGE_POINTER *mm;
  108. } vdoub;
  109.  
  110. class VMatrix
  111.  {
  112.  
  113.  protected:
  114.      long curvecind;
  115.      vdoub *v;
  116.      double HUGE_POINTER *mcheck;
  117.      void SetupVectors( int rr=1, int cc=1 );
  118.      void PurgeVectors( void );
  119.      void Replace( VMatrix &ROp );
  120.          void NewReference(VMatrix &ROp );
  121.      long mindex( int i, int j){ return ( (i-1)*c+(j-1) ); }
  122.      strtype name;
  123.      int signature;
  124.  
  125.  public:
  126.  
  127.    double Nrerror( const char *errormsg );
  128.    void Garbage( const char *errormsg);
  129.    void Garbage( void ){ Garbage(" ");}
  130.    int r,c;
  131.  
  132.    double m( int i, int j ) {          // get a value
  133. #ifndef NO_CHECKING
  134.        if( i<1 || j<1 || i>r || j>c ){
  135.           cerr << "index out of range\n";
  136.           exit(1);
  137.        }
  138. #endif
  139.        curvecind = mindex(i,j);
  140.        return v->mm[ curvecind ];
  141.    }
  142.    VMatrix& M( int i, int j ) {         // load current buffer
  143.       curvecind = mindex(i,j);
  144.       return *this;
  145.      }
  146.  
  147.    VMatrix( void );                     // constructors and destructors
  148.    VMatrix( const char *str, int i, int j);
  149.    VMatrix( VMatrix& ROp );
  150.  
  151.    ~VMatrix( void );
  152.  
  153.    double operator = ( double d ){     // write in a value
  154.      this->v->mm[curvecind] = d;
  155.      return d;
  156.    }
  157.    void operator= (VMatrix &ROp);
  158.  
  159.  
  160.     void Nameit( const char *str ) { name = str; }
  161.     void Nameit( VMatrix &mat ){ name = mat.name; }
  162.     void Nameit( strtype newname){ name = newname; }
  163.     strtype Getname( VMatrix &mat){ return mat.name; }
  164.     void Showname( void ){ name.Showname(); }
  165.     char *StringAddress( void ) { return name.StringAddress(); }
  166.  
  167.     void LoadMat(void);
  168.     void DisplayMat(void);
  169.     void InfoMat( void );
  170.     void Writeb (char *fid, VMatrix &mat);
  171.  
  172.     friend VMatrix& operator+ (VMatrix &LOp, VMatrix &ROp);
  173.     friend VMatrix& operator+ (double scalar, VMatrix &ROp);
  174.     friend VMatrix& operator+ (VMatrix &ROp, double scalar);
  175.     friend VMatrix& operator- (VMatrix &LOp, VMatrix &ROp);
  176.     friend VMatrix& operator- (double scalar, VMatrix &ROp);
  177.     friend VMatrix& operator- (VMatrix &ROp, double scalar);
  178.     friend VMatrix& operator- (VMatrix &ROp);
  179.     friend VMatrix& operator* (VMatrix &LOp, VMatrix &ROp);
  180.     friend VMatrix& operator* (double scalar, VMatrix &ROp);
  181.     friend VMatrix& operator* (VMatrix &ROp, double scalar);
  182.     friend VMatrix& operator% (VMatrix &LOp, VMatrix &ROp );
  183.     friend VMatrix& operator/ (VMatrix &LOp, VMatrix &ROp);
  184.     friend VMatrix& operator/ (VMatrix &ROp, double scalar);
  185.     friend VMatrix& operator/ (double scalar, VMatrix &ROp);
  186.  
  187. };
  188.  
  189.  
  190. //////////////// matrix stack
  191.  
  192. class MStack: public VMatrix {
  193.  
  194.   private:
  195.  
  196.    int stackloc, level;
  197.    MStack *next;
  198.    VMatrix& Pop( void );
  199.  
  200.   public:
  201.  
  202.     MStack( void );
  203.     void Push( VMatrix &ROp );
  204.  
  205.     void Inclevel();
  206.     void Declevel();
  207.     VMatrix &DecReturn( void ){
  208.        Declevel();
  209.        next->level = level;
  210.        return * ((VMatrix *) this->next);
  211.     }
  212.     VMatrix &ReturnMat( void ){
  213.        next->level = level;
  214.        return * ((VMatrix *) this->next);
  215.        }
  216.  
  217.     void PrintStack( void );
  218.     void Cleanstack( void );
  219.  
  220. };
  221.  
  222.  
  223. #else
  224.  
  225. ///////////////////////// large memory model 
  226.  
  227.  
  228.  
  229. //////////////////////////////////////// large memory model
  230.  
  231.  
  232. typedef struct vmem{
  233.   unsigned signature;
  234.   unsigned dirty;
  235.   unsigned ele_size;
  236.   unsigned ele_per_blk;
  237.   long num_ele;
  238.   unsigned cblock;
  239.   char *buf;
  240. } vmem;
  241.  
  242. typedef struct hdr {
  243.   int active;
  244.   int nrefs;
  245.   unsigned nblocks;
  246.   unsigned offset;
  247.   union { struct hdr *h;
  248.       struct vmem *v;
  249.   } next;
  250. } hdr;
  251.  
  252.  
  253. int vopen( void );
  254. int vclose (void);
  255. hdr *vmalloc ( long num_ele, unsigned int ele_size);
  256. int vfree ( hdr *p);
  257.  
  258. // the following 3 functions must be public if you want to
  259. // use the vmalloc system by itself. They are not needed globally in
  260. // the virtual matrix package.
  261.  
  262. //void *vread (hdr *p, long index);
  263. //void *vwrite (hdr *p, long index, char *thiss);
  264. //long vele(hdr *p);
  265.  
  266. class vdoub{
  267.  
  268.   protected:
  269.  
  270.     unsigned signature;// garbage flag;
  271.     hdr *hdr;          // virtual memory handle
  272.     double *cur_ele;   // current element
  273.     long  cur_index;   // current index
  274.     // static int nobj;
  275.  
  276.     friend double val( vdoub &v);
  277.  
  278.   public:
  279.  
  280.     int Garbage( void ){ return  !( signature == SIGNATURE ); }
  281.  
  282.     vdoub ( long array_size );
  283.     vdoub ( void );
  284.     vdoub ( vdoub &src );
  285.     ~vdoub( void );
  286.  
  287.     double v( long index );          // get value
  288.     vdoub& operator[]( long index ); // store value
  289.     double operator = ( double d );
  290.     double operator = ( vdoub &v );
  291. };
  292.  
  293. ///////////////////////////////////////// virtual matrix object
  294.  
  295. class VMatrix : private vdoub
  296.  {
  297.  
  298.  protected:
  299.    unsigned signature;
  300.    long mindex( int i, int j){
  301.     return   (long) (((long)(i-1))*((long)c)+((long)(j-1))) ; }
  302.    long curvecind;       // current index for vector
  303.    strtype name;
  304.    void SetupVectors( int rr=1, int cc=1 );
  305.    void PurgeVectors( void );
  306.    void Replace( VMatrix &ROp );
  307.    void NewReference( VMatrix &ROp );
  308.  
  309.  public:
  310.  
  311.    double Nrerror( const char *errormsg );
  312.    void Garbage( const char *errormsg);
  313.    void Garbage( void ){ Garbage(" ");}
  314.    int r,c;
  315.  
  316.    double m( int i, int j ) {          // get a value
  317. #ifndef NO_CHECKING
  318.       if( i<1 || j<1 || i>r || j>c ){
  319.          cerr << "index out of range\n";
  320.          exit(1);
  321.        }
  322. #endif
  323.        curvecind = mindex(i,j);
  324.        return v( curvecind );
  325.    }
  326.    VMatrix& M( int i, int j ) {         // load current buffer
  327.       curvecind = mindex(i,j);
  328.       vdoub::operator[](curvecind);
  329.       return *this;
  330.      }
  331.  
  332.    VMatrix( void );                     // constructors and destructors
  333.    VMatrix( const char *str, int i, int j);
  334.    VMatrix( VMatrix& ROp);
  335.  
  336.    ~VMatrix( void );
  337.  
  338.    double operator = ( double d ){     // write in a value
  339.      vdoub::operator[](curvecind) = d;
  340.      return d;
  341.    }
  342.    void operator= (VMatrix &ROp);
  343.  
  344.  
  345.     void Nameit( const char *str ) { name = str; }
  346.     void Nameit( VMatrix &mat ){ name = mat.name; }
  347.     void Nameit( strtype newname){ name = newname; }
  348.     strtype Getname( VMatrix &mat){ return mat.name; }
  349.     void Showname( void ){ name.Showname(); }
  350.     char *StringAddress( void ) { return name.StringAddress(); }
  351.  
  352.     void LoadMat(void);
  353.     void DisplayMat(void);
  354.     void InfoMat( void );
  355.     void Writeb (char *fid, VMatrix &mat);
  356.  
  357.     friend VMatrix& operator+ (VMatrix &LOp, VMatrix &ROp);
  358.     friend VMatrix& operator+ (double scalar, VMatrix &ROp);
  359.     friend VMatrix& operator+ (VMatrix &ROp, double scalar);
  360.     friend VMatrix& operator- (VMatrix &LOp, VMatrix &ROp);
  361.     friend VMatrix& operator- (double scalar, VMatrix &ROp);
  362.     friend VMatrix& operator- (VMatrix &ROp, double scalar);
  363.     friend VMatrix& operator- (VMatrix &ROp);
  364.     friend VMatrix& operator* (VMatrix &LOp, VMatrix &ROp);
  365.     friend VMatrix& operator* (double scalar, VMatrix &ROp);
  366.     friend VMatrix& operator* (VMatrix &ROp, double scalar);
  367.     friend VMatrix& operator% (VMatrix &LOp, VMatrix &ROp );
  368.     friend VMatrix& operator/ (VMatrix &LOp, VMatrix &ROp);
  369.     friend VMatrix& operator/ (VMatrix &ROp, double scalar);
  370.     friend VMatrix& operator/ (double scalar, VMatrix &ROp);
  371. };
  372.  
  373.  
  374. //////////////// matrix stack
  375.  
  376. class MStack: public VMatrix {
  377.  
  378.   private:
  379.  
  380.    int stackloc, level;
  381.    MStack *next;
  382.    VMatrix& Pop( void );
  383.  
  384.   public:
  385.  
  386.     MStack( void );
  387.     void Push( VMatrix &ROp );
  388.  
  389.     void Inclevel();
  390.     void Declevel();
  391.     VMatrix &DecReturn( void ){
  392.        Declevel();
  393.        next->level = level;
  394.        return * ((VMatrix *) this->next);
  395.     }
  396.     VMatrix &ReturnMat( void ){
  397.        next->level = level;
  398.        return * ((VMatrix *) this->next);
  399.        }
  400.  
  401.     void PrintStack( void );
  402.     void Cleanstack( void );
  403.  
  404. };
  405.  
  406. ///////////////////////////////////////////// end of large memory model
  407.  
  408. #endif
  409.  
  410. extern MStack *Dispatch;
  411.  
  412. typedef enum boolean { FFALSE, TTRUE } boolean;
  413.  
  414. ///////////////////////////// display control
  415.  
  416. int Setwid( int w );                      // set display width
  417. int Setdec( int d );                      // set decimals
  418. int Getwid( void  );                      // report display width
  419. int Getdec( void  );                      // report decimals
  420.  
  421. ////////////////////////// io
  422.  
  423. VMatrix& Reada( char *fid);               // read ascii file
  424. VMatrix& Readb( char *fid);               // read binary file
  425. void Writea( char *fid, VMatrix &mat);    // write ascii file
  426. //void VMatrix::Writeb( char *fid, VMatrix &mat)   // write binary file
  427.  
  428. /////////////////////////// sorting, subsetting, and conatenation
  429. //   sort    order == 0 =>  sort col c and exchange rows
  430. //           order != 0 =>  sort row c and exchange cols
  431. //
  432. //   submat  r,c is bottom right corner,   lr,lc is upper left corner
  433. //
  434. //   Ch   horozontal concatenation
  435. //   Cv   vertical concatentation
  436. //
  437.  
  438. VMatrix& MSort( VMatrix &a, int col, int order=0);
  439. VMatrix& Submat( VMatrix &a, int r, int c, int lr=1, int lc=1);
  440. VMatrix& Ch( VMatrix &a, VMatrix &b );
  441. VMatrix& Cv( VMatrix &a, VMatrix &b );
  442.  
  443. /////////////////////////// special matrices
  444. //
  445. //   Tran    transpose of matrix
  446. //   Mexp    elementwise exponential
  447. //   Mabs    elementwise absolute value
  448. //   Mlog    elementwise log
  449. //   Msqrt   elementwise sqrt
  450. //   Trace   trace of square matrix
  451. //   Ident   identity matrix
  452. //   Helm    Helmert matrix
  453. //   Fill    constant matrix
  454. //   Index   build an index matrix: if lower>upper step downward
  455. //
  456.  
  457. VMatrix& Tran(VMatrix &ROp );
  458. VMatrix& Mexp(VMatrix &ROp );
  459. VMatrix& Mabs(VMatrix &ROp );
  460. VMatrix& Mlog(VMatrix &ROp );
  461. VMatrix& Msqrt(VMatrix &ROp );
  462. double Trace(VMatrix &ROp );
  463. VMatrix& Ident(int n );
  464. VMatrix& Helm( int n );
  465. VMatrix& Fill(int r, int c, double d );
  466. VMatrix& Index( int lower, int upper, int step = 1);
  467.  
  468. /////////////////////////// inversion and decomposition
  469. //
  470. //     Sweep       sweep on diagonal elements k1 to k2
  471. //     Inv         matrix inverse using sweep(1,ROp.c,ROp)
  472. //     Kron        Kroniker (direct) product
  473. //     Det         Determinant
  474. //     Cholesky    upper triangular S where ROp = S'S, for symmetric ROp
  475. //     QR          ROp( rxc, r>c ) = Q(rxc) R(cxc), and Q'Q = Ident(c)
  476. //                 makeq = TTRUE => make Q, it is garbage otherwise
  477. //     Svd         ROp = USTran(V),
  478. //                 where U'U = I, V'V=I, S= Column of singular values
  479. //                 makeu = TTrue => Compute U, it is garbage otherwise
  480. //                 makev = TTrue => Compute V, it is garbage otherwise
  481. //     Ginv        See Svd, Ginv(ROp) = V Inv(Diag(S+)) Tran(U)
  482. //     Fft         Almost fast Fourier transform, can be slow if
  483. //                 n > 1000 or prime factors of n > 19, does not require
  484. //                 n to be a power of 2
  485. //                 INZEE = TTRUE => compute fft
  486. //                 INZEE = FFALSE=> compute ifft
  487. //
  488.  
  489. VMatrix& Sweep( int k1, int k2, VMatrix& ROp); /* sweep out a row */
  490. VMatrix& Inv( VMatrix &ROp ); /*matrix inversion using sweep */
  491. VMatrix& Kron( VMatrix &a, VMatrix &b );
  492. double Det( VMatrix &ROp );
  493. VMatrix& Cholesky(VMatrix& ROp);
  494. void QR( VMatrix& ROp, VMatrix& Q, VMatrix& R, boolean makeq = TTRUE);
  495. int Svd( VMatrix &A, VMatrix &U, VMatrix &S, VMatrix &V,
  496.           boolean makeu = TTRUE, boolean makev = TTRUE);
  497. VMatrix& Ginv( VMatrix& ROp );
  498. VMatrix& Fft( VMatrix &ROp, boolean INZEE = TTRUE);
  499.  
  500.  
  501. ////////////////////////// reshaping functions
  502.  
  503. VMatrix& Vec( VMatrix& ROp );      // send matrix to vector
  504.                                    // stack columns into an (r*c)x1
  505. VMatrix& Vecdiag( VMatrix& ROp );  // extract diagonal into a vector
  506. VMatrix& Diag( VMatrix& ROp );     // create a diagonal matrix from
  507.                                    // square matrix or column vector
  508. VMatrix& Shape( VMatrix& ROp, int nrows = 1 );       // reshape into nrows
  509.  
  510. ////////////////////////// summation functions
  511.  
  512. typedef enum margins { ALL, ROWS, COLUMNS } margins; // summation margins
  513.  
  514. VMatrix& Sum( VMatrix& ROp, margins marg = ALL );    // sums over margins
  515. VMatrix& Sumsq( VMatrix& ROp, margins marg = ALL );  // sum of squares
  516. VMatrix& Cusum( VMatrix& ROp);                       // accumulate along rows
  517.  
  518.  
  519. /////////////////////////// max and mins
  520. //
  521. // if marg = ALL      return 3x1   [ maxr, maxc, max element ]
  522. // if marg = ROWS     return 3xc   Tran([ maxr, col=1..c, max element ])
  523. // if marg = COLUMNS  return rx3   [ row=1..r, maxc, max element]
  524. //
  525. // same structure for mins
  526. //
  527.  
  528. VMatrix& Mmax( VMatrix& ROp, margins marg=ALL );   // matrix max
  529. VMatrix& Mmin( VMatrix& ROp, margins marg=ALL );   //  matrix min
  530.  
  531. ////////////////////////// row and column operations
  532. //
  533. // Crow      c*r1
  534. // Srow      swap r1 with r2
  535. // Lrow      r2 + c*r1
  536. // Ccol      c*c1
  537. // Scol      swap c1 with c2
  538. // Lcol      c2 + c*c1
  539. //
  540. // note default values for row and col are out of range, so they
  541. // must be supplied. This is for error checking.
  542. // default constants perform no changes.
  543. // !!!!!!!!!!!!! these functions operate directly on matrix
  544. //////////////////////////
  545.  
  546. void Crow( VMatrix& ROp, int row=0, double c=1.0);
  547. void Srow( VMatrix &ROp, int row1 = 0, int row2 = 0);
  548. void Lrow( VMatrix &ROp, int row1 = 0, int row2 = 0, double c=0.0);
  549. void Ccol( VMatrix& ROp, int col=0, double c=1.0);
  550. void Scol( VMatrix &ROp, int col1 = 0, int col2 = 0);
  551. void Lcol( VMatrix &ROp, int col1 = 0, int col2 = 0, double c=0.0);
  552.  
  553. //////////////////////////////////////////////////////////////
  554. //////////////////////////// XYplot objects ////////////////
  555. //////////////////////////////////////////////////////////////
  556.  
  557.  
  558. #ifdef VIRTGRAF
  559.  
  560. #if !(__BCPLUSPLUS__ || __TCPLUSPLUS__)
  561. #error GMatrix class requires Borland BGI functions
  562. #endif
  563.  
  564.  
  565. #ifdef __TINY__
  566. #error GMatrix class will not work in the tiny model.
  567. #endif
  568.  
  569. #include <conio.h>
  570. #include <stdarg.h>
  571. #include <graphics.h>
  572.  
  573. // the Axis class is called from the GMatrix Class. It
  574. // is not needed otherwise, and will not be commented
  575. class Axis
  576. {
  577.    protected:
  578.      // uses fortran translations of Algorithm AS 168 of Applied Statistics
  579.       double valmin, step;
  580.       double *vals, fmn, fmx, offset;
  581.       int nvals, irprin, maxpr, ifact;
  582.       VMatrix *Vals;
  583.       int nplt, mpv, ir, ifault , iv;
  584.       double dmax( double x, double y);
  585.       void scale(double fmn, double fmx, int nplt, int mpv,
  586.                double *valmin, double *step, int *nvals,int *ir, int *ifault);
  587.       void axis(double valmin,double step,int nvals, int maxpr,int ir,
  588.                int *irprin, double *offset, int *ifact, double *vals, int iv,
  589.                int * ifault);
  590.       void getvals(double fmn,double fmx,int n, double *vals,
  591.                    double *offset,int *ifact,int *nvals,int *irprin);
  592.     struct linesettingstype lineinfo;
  593.  
  594.    public:
  595.       Axis( VMatrix &grf_vec, int col, int pixels, int pxlspplot);
  596.       ~Axis( void );
  597.  
  598.       virtual void Show( void )
  599.         {
  600.           restorecrtmode();
  601.           Dispatch->Nrerror("AXIS: trying to show an undefined axis object");
  602.         }
  603.       strtype GetAxisLabel( strtype &name );
  604.       double Rescale( double x );
  605.  
  606. };
  607. class YAxis:public Axis
  608. {
  609.    private:
  610.      double deltay;
  611.      int h, w, xlen, ylen, bmarg, umarg, lmarg, rmarg;
  612.  
  613.    public:
  614.      double miny, maxy;
  615.  
  616.      void Show( boolean gridon );
  617.      YAxis( VMatrix &grf, int xxlen,  int yylen,  int ww, int hh,
  618.             int bbmarg,   int uumarg, int llmarg, int rrmarg);
  619. };
  620.  
  621. class XAxis:public Axis
  622. {
  623.    private:
  624.      double deltax;
  625.      int w, h, xlen, ylen, bmarg, umarg, lmarg, rmarg;
  626.  
  627.    public:
  628.      double minx, maxx;
  629.  
  630.      void Show( boolean gridon );
  631.      XAxis( VMatrix &grf, int xxlen,  int yylen, int ww, int hh,
  632.             int bbmarg,   int uumarg, int llmarg, int rrmarg);
  633. };
  634.  
  635.  
  636. ///////////////////////////////  graph matrix class
  637.  
  638. class GMatrix
  639. {
  640.   private:
  641.     // Borland graphics information. bgi files must be available
  642.     int    GraphDriver;
  643.     int    GraphMode;
  644.     int    MaxX, MaxY;
  645.     int    MaxColors;
  646.     int    ErrorCode;
  647.     struct linesettingstype lineinfo;
  648.     struct viewporttype viewinfo;
  649.  
  650.  
  651.     // reference lines. can have at most 20 reference lines
  652.     double *hrefs;
  653.     double *vrefs;
  654.     int nvrefs, nhrefs;
  655.  
  656.     // output a line, and pause function ESC stops program
  657.     int  gprintf(int *xloc, int *yloc, char *fmt, ... );
  658.     void Pause();
  659.  
  660.     // graph is stored in a VMatrix: [graphid, symbol, x, y] 4 cols
  661.     int    graphnum;        // number of graphs in grf;
  662.     VMatrix *grf;
  663.  
  664.     // plot a point on the screen
  665.     void plotpoint( int ix, int iy, int symbol);
  666.  
  667.   public:
  668.  
  669.     // constructors and destructors
  670.  
  671.     GMatrix( void );
  672.     GMatrix( VMatrix &ROp, int symbol= -' '); // ROp should be rx2 matrix
  673.                                               // column 1 is x, col 2 is y
  674.     ~GMatrix( void );
  675.  
  676.     // display a graph
  677.     void Show( void );
  678.  
  679.     // add a new vector to plot
  680.     void AddVec( VMatrix &ROp, int symbol = -' ');
  681.  
  682.     // annotation options
  683.  
  684.     strtype *title, *title2, *xname, *yname, *PathToDriver;
  685.     boolean RectangleOn, YGridOn, XGridOn;
  686.     void Href( double href );
  687.     void Vref( double vref );
  688.     int ClearHref( void ){ int t=nhrefs; nhrefs = -1; return t;}
  689.     int ClearVref( void ){ int t=nvrefs; nvrefs = -1; return t;}
  690.  
  691.     // save the grf matrix
  692.     void SaveGraph( char *fid ) { Writea( fid, *grf ); }
  693. };
  694.  
  695. #endif
  696.